package tree

func isValidBST(root *TreeNode) bool {
	return check(root, -1<<63, 1<<63-1)
}

func check(root *TreeNode, lower, upper int) bool {
	if root == nil {
		return true
	}
	if root.Val <= lower || root.Val >= upper {
		return false
	}
	return check(root.Left, lower, root.Val) && check(root.Right, root.Val, upper)
}

